package com.ess.user.service.menu;

import com.ess.base.service.impl.BaseServiceImpl;
import com.ess.constants.Constants;
import com.ess.user.mapper.MenuMapper;
import com.ess.user.po.Menu;
import com.github.abel533.entity.Example;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("menuService")
public class MenuServiceImpl extends BaseServiceImpl<Menu> implements MenuService {

    @Autowired
    private MenuMapper menuMapper;

    /**
     * 分页查询用户信息 可以设置排序，模糊查询
     *
     * @param page
     * @param rows
     * @param record
     * @return
     */
    @Override
    public PageInfo<Menu> queryPageListByCondition(int page, int rows, Menu record) {
        PageHelper.startPage(page, rows);
        Example example = new Example(Menu.class);
        example.setOrderByClause(Constants.ORDER_UPDATE_DESC);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("isDeleted", Constants.STRING_ZERO);
        if (StringUtils.isNotBlank(record.getMenuName())) {
            criteria.andLike("menuName", "%" + record.getMenuName() + "%");
        }
        if (StringUtils.isNotBlank(record.getMenuLink())) {
            criteria.andEqualTo("menuLink", record.getMenuLink());
        }
        if (StringUtils.isNotBlank(record.getMenuLevel())) {
            criteria.andEqualTo("menuLevel", record.getMenuLevel());
        }
        if (StringUtils.isNotBlank(record.getMenuType())) {
            criteria.andEqualTo("menuType", record.getMenuType());
        }
        if (StringUtils.isNotBlank(record.getParentSid())) {
            criteria.andEqualTo("parentSid", record.getParentSid());
        }
        List<Menu> list = super.mapper.selectByExample(example);
        return new PageInfo<Menu>(list);
    }

}

